package com.hengpeng.itfin.persist.impl;

import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.hengpeng.common.persist.AbstractDao;
import com.hengpeng.common.persist.entity.AbstractEntity.BoolValue;
import com.hengpeng.common.persist.query.DynamicQuery;
import com.hengpeng.itfin.persist.ImprestDao;
import com.hengpeng.itfinbase.persist.Payment;
import com.hengpeng.itfinbase.persist.Payment.PayStatus;

@Repository
public class ImprestDaoImpl extends AbstractDao<Payment> implements ImprestDao
{
	@Override
	public List<Payment> findFillPenNumber(String storeId, PayStatus state, Date startDate, Date endDate)
	{
		return super.findAllByNamedQuery("imprest.findFillPenNumber", storeId, state, startDate, endDate);
	}

	public List<Payment> findUnStatisticsImprest(Integer batch)
	{
		DynamicQuery query = new DynamicQuery(Payment.class);
		query.eq("payStatus", PayStatus.SUCCESS);
		query.eq("isStatistics", BoolValue.NO);
		query.setPageSize(batch);
		return super.findAllByDynamicQuery(query);
	}

	@Override
	public Long sumFillMoneyByBetCardNo(String betCardNo, PayStatus state, Date startDate, Date endDate)
	{
		return super.countByNamedQuery("Imprest.sumFillMoneyByBetCardNo", betCardNo, PayStatus.SUCCESS, startDate,
				endDate);
	}
	
	public Payment getImprest(String storeId,String payOrderId)
	{
		DynamicQuery query = new DynamicQuery(Payment.class);
		query.eq("storeId", storeId);
		query.eq("payOrderId",payOrderId);
		
		return super.getSingleByDynamicQuery(query);
	}

}
